/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 黎鹤舞
 * Date: 2023-11-18
 * Time: 15:29
 */

class Cycle implements Shape {
    @Override
    public void draw() {
        System.out.println("圆形！！！");
    }
}

class Rect implements Shape {
    @Override
    public void draw() {
        System.out.println("矩形！！！！");
    }
}

class Triangles implements Shape {
    @Override
    public void draw() {
        System.out.println("三角形！！！");
    }
}

//这里测试的是接口的使用（向上转型）
public class Test {

    //写一个在main函数的静态方法（因为static修饰的类 只能调用静态方法）
    public static void fun(Shape shape) {      //这里参数是父类，调用函数时发生向上转型
        shape.draw();
    }

    public static void main(String[] args) {

        //实例化三个不同类的对象
        Cycle cycle = new Cycle();
        Rect rect = new Rect();
        Triangles triangles = new Triangles();

        //方法一：
        //均进行fun打印
        fun(cycle);
        fun(rect);
        fun(triangles);
        System.out.println("================");

        //方法二:
        //利用数组遍历
        Shape[] shapes = {cycle,rect,triangles};
        //加强for循环（foreach）
        for(Shape shape : shapes) {
            shape.draw();
        }

        boolean b = cycle instanceof Shape;
        System.out.println("cycle instanceof Shape is :" + b);
    }
}
